package cn.tedu.ivos.dict.dao.repository.impl;

import cn.tedu.ivos.base.pojo.vo.PageData;
import cn.tedu.ivos.base.utils.PageInfoToPageDataConverter;
import cn.tedu.ivos.dict.dao.mapper.DictMapper;
import cn.tedu.ivos.dict.dao.repository.DictDao;
import cn.tedu.ivos.dict.pojo.dto.DictQueryParam;
import cn.tedu.ivos.dict.pojo.entity.Dict;
import cn.tedu.ivos.dict.pojo.vo.DictVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class DictDaoImpl implements DictDao {
    @Autowired
    private DictMapper dictMapper;
    @Override
    public PageData<DictVO> selectDict(DictQueryParam dictQuery) {
        PageHelper.startPage(dictQuery.getPageNum(),dictQuery.getPageSize());
        List<DictVO> list = dictMapper.selectDict(dictQuery);
        PageInfo<DictVO> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    @Override
    public List<DictVO> selectDictByCode(DictQueryParam dictQuery) {
        return dictMapper.selectDictByCode(dictQuery);
    }

    @Override
    public int insert(Dict dict) {
        return dictMapper.insert(dict);
    }

    @Override
    public int update(Dict dict) {
        return dictMapper.update(dict);
    }

    @Override
    public int deleteById(Long id) {
        return dictMapper.deleteById(id);
    }
}
